<template>
  <div class="status-header">
    <!-- 左侧Logo和时间 -->
    <div class="header-left">
      <img src="../assets/logo.png"  class="logo" alt="公司Logo">
      <div class="time-info">
        <div class="current-time">{{ currentTime }}</div>
        <div class="current-date">{{ currentDate }}</div>
      </div>
    </div>

    <!-- 中间标题 -->
    <h1 class="main-title">IIMS云端数据监控平台</h1>

    <!-- 右侧状态信息 -->
    <div class="header-right">
      <div class="status-item">
        <span class="status-label">系统状态:</span>
        <span class="status-value normal">运行正常</span>
      </div>
      <div class="status-item">
        <span class="status-label">数据更新:</span>
        <span class="status-value">{{ lastUpdateTime }}</span>
      </div>
      <el-button
          type="primary"
          size="small"
          @click="toggleFullscreen"
          class="fullscreen-btn"
      >
        <i :class="isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"></i>
        {{ isFullscreen ? '退出' : '全屏' }}
      </el-button>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue'

export default {
  emits: ['toggle-fullscreen'], // 声明自定义事件

  setup(props, { emit }) {
    const currentTime = ref('')
    const currentDate = ref('')
    const lastUpdateTime = ref('刚刚更新')
    const isFullscreen = ref(false)

    // 更新时间
    const updateTime = () => {
      const now = new Date()
      currentTime.value  = now.toLocaleTimeString()
      currentDate.value  = now.toLocaleDateString('zh-CN',  {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        weekday: 'short'
      })
    }

    // 切换全屏状态
    const toggleFullscreen = () => {
      emit('toggle-fullscreen') // 触发父组件事件
      isFullscreen.value  = !isFullscreen.value
    }

    // 初始化定时器
    onMounted(() => {
      updateTime()
      const timer = setInterval(updateTime, 1000)

      // 模拟数据更新时间
      setInterval(() => {
        lastUpdateTime.value  = new Date().toLocaleTimeString('zh-CN', {
          hour: '2-digit',
          minute: '2-digit'
        }) + '更新'
      }, 60000)

      onUnmounted(() => clearInterval(timer))
    })

    return {
      currentTime,
      currentDate,
      lastUpdateTime,
      isFullscreen,
      toggleFullscreen
    }
  }
}
</script>

<style scoped>
.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  padding: 0 30px;
  background: rgba(0, 30, 60, 0.7);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(79, 216, 222, 0.2);
}

.header-left {
  display: flex;
  align-items: center;
  width: 300px;
}

.logo {
  height: 40px;
  margin-right: 20px;
}

.time-info {
  display: flex;
  flex-direction: column;
}

.current-time {
  font-size: 16px;
  font-weight: bold;
  color: #4fd8de;
}

.current-date {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.main-title {
  font-size: 30px;
  font-weight: bold;
  background: linear-gradient(90deg, #4fd8de, #0b5de8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 10px rgba(79, 216, 222, 0.3);
  letter-spacing: 2px;
}

.header-right {
  display: flex;
  width: 300px;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
}

.status-item {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.status-value {
  font-size: 16px;
  font-weight: bold;
}

.status-value.normal  {
  color: #00e676;
}

.status-value.warning  {
  color: #ff9100;
}

.status-value.error  {
  color: #ff5252;
}

.fullscreen-btn {
  background: rgba(13, 42, 67, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  transition: all 0.3s ease;
  height: 32px;
}

.fullscreen-btn:hover {
  background: rgba(30, 144, 255, 0.8);
  border-color: rgba(30, 144, 255, 0.8);
}

</style>